/*
* @author : TF-BJ-C064
* @creation : 2014-7-11 上午9:35:07
* @description : 
*
*/

package com.bean;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import com.bean.billtool.CalcBill;

/**
 * 订单的计费模块
 * <p>Title: ParkOrderBilling</p>
 * <p>Description: 
 * 		根据ParkOrderExt提供的数据计算费用
 * 	</p>
 * <p>Company: www.teleframe.cn</p> 
 * @author	lijian
 * @date	2014-7-11
 */
public class ParkOrderBilling implements java.io.Serializable{
	
	/** serialVersionUID*/
	private static final long serialVersionUID = -3623602811021478566L;
	
	private CalcBill caleBillTool = new CalcBill();

	/**
	 * 计算费用
	 * <p>Title: CalcOrderBilling</p>
	 * <p>Description: 
	 * 		计算方式：安装ParkOrderExt给出的计费单位进行核算，目前是分为白天和晚上
	 * </p>
	 * 	
	private String dayStartTime;//白天开始时间
	private String dayEndTime;//白天结束时间
	private String nightStartTime;//晚上开始时间
	private String nightTndTime;//晚上结束时间

	private float dayTimeUnit = 0;//白天记时单位
	private float nightTimeUnit = 0;//晚上记时单位
	private float dayPrice = 0;//白天单价
	private float nightPrice = 0;//晚上单价
	 * @param parkOrderExt 
	 * 			订单的扩展字段对象，不能为空
	 * @param startTime
	 * 			订单的开始时间 
	 * @param endTime
	 * 			订单的结束时间
	 * @return
	 * 			计算后的总金额，保留2位小数位
	 */
	public Double CalcOrderBilling(ParkOrderExt parkOrderExt, Timestamp startTime, Timestamp endTime){
		Double total=100.0;
	
		long tStartSec = startTime.getTime();//停车开始时间(秒)
		long tStopSec = endTime.getTime();//停车结束时间(秒)
		
		int  ucDayStartHour = parkOrderExt.getUcDayStartHour(); 	//白天开始计费--时
		int ucDayStartMinute =parkOrderExt.getUcDayStartMinute();	//白天开始计费--分
		int ucDayStopHour = parkOrderExt.getUcDayStopHour();			//白天结束计费--时
		int ucDayStopMinute = parkOrderExt.getUcDayStopMinute();		//白天结束计费--分
		
		int ucNightStartHour = parkOrderExt.getUcNightStartHour();		//夜晚开始计费--时
		int ucNightStartMinute = parkOrderExt.getUcNightStartMinute();		//夜晚开始计费--分
		int ucNightStopHour = parkOrderExt.getUcNightStopHour();		//夜晚结束计费--时
		int ucNightStopMinute = parkOrderExt.getUcNightStopMinute();		//夜晚结束计费--分
		
		double pDayUnit = parkOrderExt.getDayTimeUnit();			//白天计费单位时长(小时)
		double pNightUnit = parkOrderExt.getNightTimeUnit();			//夜晚计费单位时长(小时)
		
		double nDayPrice = parkOrderExt.getDayPrice();			//白天计费单位单价(元)
		double nNightPrice = parkOrderExt.getNightPrice();			//夜晚计费单位单价(元)
		double nGratuity = parkOrderExt.getnGratuity();			//小费(元)
		int nIgoreOverTime = parkOrderExt.getnIgoreOverTime();			//一个计时单位内可以忽略的计费时长(分钟)
		int iIgoreTime = parkOrderExt.getiIgoreTime();				//总时长小于这个则不收费(分)
		
		total = (double) caleBillTool.calc_park_bill(tStartSec, tStopSec,
				ucDayStartHour, ucDayStartMinute, ucDayStopHour, ucDayStopMinute,
				ucNightStartHour, ucNightStartMinute, ucNightStopHour, ucNightStopMinute, 
				pDayUnit, pNightUnit, nDayPrice, nNightPrice, nGratuity, nIgoreOverTime, iIgoreTime);
		
		//一共多少费用 total=白天费用+晚上费用
		
		return  total;
	}

	public ParkOrderBilling(){
		
	}
	
	
	public static void main(String[] argv) throws ParseException{
		String jsonString="{\"dayStartTime\":\"9:00\",\"dayEndTime\":\"17:00\",\"dayPrice\":0.5,\"dayTimeUnit\":1, \"nightStartTime\":\"20:00\",\"nightEndTime\":\"6:00\",\"nightPrice\":0.2,\"nightTimeUnit\":1}";
		ParkOrderExt parkOrderExt = ParkOrderExt.newInstance(jsonString);
		String st = "2014-08-01 12:15";
		String et = "2014-08-06 17:25";
		SimpleDateFormat sdf =  new SimpleDateFormat("yyyy-MM-dd HH:mm");
		Timestamp startTime = new Timestamp(sdf.parse(st).getTime()); 
		Timestamp endTime = new Timestamp(sdf.parse(et).getTime()); 
		
		System.out.println("startTime="+startTime.toLocaleString());
		System.out.println("endTime="+endTime.toLocaleString());
		
		ParkOrderBilling pob = new ParkOrderBilling();
		Double sum = pob.CalcOrderBilling(parkOrderExt, startTime, endTime);
		
		System.out.println("sum="+sum);
		
	}
	
	
}



